#if !defined(_MYWEBSERVER_H_INCLUDED_)
#define _MYWEBSERVER_H_INCLUDED_
#pragma once
#include "DrvFrame.h"

//
class CMyChannel;
class CZObjectPool;
class CMyConfig;
#define MAX_DATASET_COUNT 10
#define MAX_ITEM_PER_DATASET 512
class CMyServer 
{
public:
	CMyServer(CMyChannel* pMyChannel);
	~CMyServer();

public:
	int Initialize(CMyConfig* pConfig);
	int Initialize_Inner(CMyConfig* pConfig);
	void Close();
	int Start();
	int Stop();
	void Running();
	void Deal_Asdu_Recv();

public:
	CMyChannel* m_pMyChannel;
	ISLApp*		m_pIApp;
	
	CMyConfig*	m_pConfig;

	//
	CMyNode*	m_pDbRoot;
	CZObjectPool*	m_pZPoolDeal;

	//
	// UA_ServerConfig* ua_pConfig;
	UA_Server* ua_pServer;
private:
	UA_NodeId connectionIdent;
	struct PublishDataSet {
		UA_NodeId publishedDataSetIdent;
		unsigned variableCount;
		bool used;
	};
	PublishDataSet publishedDataSetIdents[MAX_DATASET_COUNT];
	UA_NodeId writerGroupIdent;
	UA_Boolean useJson;// = true;
protected:
	friend class CMyNode;
	void addPubSubConnection(UA_Server *server, char *addressUrl);
	void addPublishedDataSet(UA_Server *server, int index);
	void addDataSetField(UA_Server *server);
	void addDataSetField(UA_Server *server, const char* field_name, UA_NodeId& field_id);
	void addWriterGroup(UA_Server *server, char *topic, int interval);
	void addDataSetWriter(UA_Server *server, char *topic, int index);
	void addAllNodes(UA_Server *server);
public:
	UA_Boolean m_bServerRunning;
	volatile bool m_bThreadRunning;
	volatile bool m_bThreadExitFlag;
	FSTHREAD_POBJECT	m_pThread;
	static FSTHREAD_RET_TYPE _ThreadBegin(void* pVoid);

	UA_UsernamePasswordLogin m_Logins[10];
};

#endif //_MYWEBSERVER_H_INCLUDED_
